package com.sxit.tdf.server.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sxit.tdf.server.entity.Role;
import com.sxit.tdf.server.entity.bo.RoleInfoBo;
import com.sxit.tdf.server.entity.bo.SimpleRoleListBo;
import com.sxit.tdf.server.exception.TdfException;
import com.sxit.tdf.server.mapper.RoleMapper;
import com.sxit.tdf.server.service.IRoleService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 角色表 服务实现类
 *
 * @author 橙子高🍊
 * @since 2022-02-05
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {
  @Override
  public List<SimpleRoleListBo> getAllSimpleRoleListBo() {
    return baseMapper.getAllSimpleRoleListBo();
  }

  @Override
  public List<RoleInfoBo> getRoleList() {
    return baseMapper.getRoleList();
  }

  @Override
  public Boolean deleteById(int id) {

    Boolean delete = baseMapper.isDelete(id);
    if (delete) {
      int i = baseMapper.deleteById(id);
      return i == 1;
    } else {
      throw new TdfException("还有用户属于该角色,请先更改用户角色信息");
    }
  }
}
